<!-- 客服列表信息 -->
<template>
  <div class="table">
    <el-tabs v-model="activeName" @tab-click="handleChangeTabs">
      <el-tab-pane label="客服列表" name="one">
        <div class="container">
          <div class="crumbs">
            <el-breadcrumb separator="/">
              <el-breadcrumb-item>
                <el-icon>
                  <Search />
                </el-icon> 查询条件：
              </el-breadcrumb-item>
            </el-breadcrumb>
          </div>
          <el-row :gutter="10">
            <el-col :xl="6" :lg="6" :md="12" :sm="24" style="margin-bottom:10px">
              <el-select v-model.trim="searchCondition.customer_service_category_id" placeholder="客服分类" clearable
                class="">
                <el-option v-for="item in state.selectCustomerClass" :label="item.name" :value="item.id" :key="item.id">
                </el-option>
              </el-select>
            </el-col>
            <el-col :xl="6" :lg="6" :md="12" :sm="24" style="margin-bottom:10px">
              <el-input v-model.trim="searchCondition.name" placeholder="客服名称" clearable></el-input>
            </el-col>
            <el-col :xl="6" :lg="6" :md="12" :sm="24" style="margin-bottom:10px">
              <el-input v-model.trim="searchCondition.mobile" placeholder="客服手机号" clearable></el-input>
            </el-col>
            <el-col :xl="6" :lg="6" :md="12" :sm="24" style="margin-bottom:10px">
              <el-button type="success" :icon="Search" :disabled="disabledbtn" @click="searchInfo">搜索</el-button>
              <el-button type="warning" :icon="Refresh" :disabled="disabledbtn" @click="resetSearch">重置</el-button>
            </el-col>
          </el-row>
          <div class="crumbs">
            <el-breadcrumb separator="/">
              <el-breadcrumb-item>查询结果：</el-breadcrumb-item>
            </el-breadcrumb>
          </div>
          <div class="handle-box">
            <el-button type="primary" :icon="Plus" class="mr10" :disabled="disabledbtn" @click="setActiveName('two')">新增
            </el-button>
            <el-popconfirm placement="top" width="160" title="你确定要删除吗?"
              @confirm="batchDelete('deleteCustomerServiceInfo')">
              <template #reference>
                <el-button type="danger" :icon="Delete" class="mr10" :disabled="disabledbtn">批量删除
                </el-button>
              </template>
            </el-popconfirm>
          </div>
          <el-table :data="tableState.tableList" border class="table" ref="multipleTableRef" v-loading="tableLoading"
            :reserve-selection="true" @row-dblclick="rowDblclick">
            <el-table-column type="index" align="center"> </el-table-column>
            <el-table-column type="selection" width="55" align="center"></el-table-column>
            <el-table-column prop="customer_service_category_name" label="客服分类" align="center">
            </el-table-column>
            <el-table-column prop="name" label="客服名称" align="center">
            </el-table-column>
            <el-table-column prop="mobile" label="客服手机号" align="center">
            </el-table-column>
            <el-table-column prop="sort" label="排序" align="center">
              <template #default="scope">
                <div class="">
                  <el-input v-model.trim.number="scope.row.sort" placeholder="请输入内容" @change="handleSort(scope.row)">
                  </el-input>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="180" align="center">
              <template #default="scope">
                <el-button type="primary" size="small" text :icon="View" @click="handleViewEdit(scope.row, 'view')">
                  查看
                </el-button>
                <el-button type="primary" size="small" text :icon="Edit" @click="handleViewEdit(scope.row, 'edit')">
                  编辑
                </el-button>
                <div class="mlr10 display-inline-block">
                  <el-popconfirm placement="top" width="160" title="你确定要删除吗?"
                    @confirm="deleteInfo('deleteCustomerServiceInfo', [id])">
                    <template #reference>
                      <el-button text :icon="Delete" size="small" class="red" @click="id = scope.row.id">删除
                      </el-button>
                    </template>
                  </el-popconfirm>
                </div>
              </template>
            </el-table-column>
          </el-table>
          <div class="pagination">
            <el-pagination background @update:current-page="handleCurrentChange" @update:page-size="handleSizeChange"
              layout="total, sizes, prev, pager, next, jumper" :page-size="searchCondition.size"
              :current-page="searchCondition.current" :page-sizes="pageSizes" :total="total"
              :hide-on-single-page="false">
            </el-pagination>
          </div>
        </div>
      </el-tab-pane>
      <el-tab-pane label="客服详情" name="two">
        <div class="container">
          <el-form ref="mobilePhoneInfoFormRef" :model="mobilePhoneInfoForm" :rules="rules" v-loading="formLoading"
            label-width="150px">
            <el-divider content-position="left"><span class="title-left-color">基本信息</span></el-divider>
            <el-row :gutter="10">
              <el-col :span="9">
                <el-form-item label="客服分类：" prop="customer_service_category_id">
                  <el-select v-model.trim="mobilePhoneInfoForm.customer_service_category_id" placeholder="客服分类"
                    class="">
                    <el-option v-for="item in state.selectCustomerClass" :label="item.name" :value="item.id"
                      :key="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-button type="primary" plain
                  @click="() => { getListDataInfo('getCustomerServiceCategoryInfo', state, 'selectCustomerClass') }">刷新</el-button>
              </el-col>
              <el-col :span="10">
                <el-form-item label="客服名称：" prop="name">
                  <el-input v-model="mobilePhoneInfoForm.name" placeholder="客服名称"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="10">
              <el-col :span="10">
                <el-form-item label="客服手机号：" prop="mobile">
                  <el-input v-model.trim="mobilePhoneInfoForm.mobile" placeholder="客服手机号"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="10">
                <el-form-item label="排序：" prop="sort">
                  <el-input v-model.trim="mobilePhoneInfoForm.sort" placeholder="排序"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <div class="footer-center">
            <el-button :disabled="disabledbtn" @click="cancelSubmit">取 消</el-button>
            <el-button type="primary" :disabled="disabledbtn" v-if="!isDisabledbtn"
              @click="submitForm('commonCustomerServiceInfo', getTableInfo)">
              确 定
            </el-button>
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<script setup>
import { reactive, ref, toRef } from 'vue';
import { ElMessage } from 'element-plus';
import { View, Delete, Edit, Search, Plus, Refresh } from '@element-plus/icons-vue';
import { api as Request } from '@/utils/api';
import { useTable } from '@/hooks/useTable.js';
import { useTabsForm } from '@/hooks/useTabsForm.js';
import { useSort } from '@/hooks/useSort.js';
import { useListData } from '@/hooks/network/useListData.js';
import useRules from '@/hooks/useRules.js';

const disabledbtn = ref(false);/*  按钮可用与不可用 */
const formLoading = ref(false);/*  对话框中数据提交加载 */
let { total, pageSizes, multipleTableRef, tableLoading, tableState, searchCondition,
  handleCurrentChange, handleSizeChange, getTableInfo, searchInfo, resetSearch, batchDelete, deleteInfo, rowDblclick } =
  useTable({
    customer_service_category_id: '',
    name: '',
    mobile: '',
    current: 1,
    size: 10
  }, 'getCustomerServiceInfo', disabledbtn);
let { formRef: mobilePhoneInfoFormRef, formData: mobilePhoneInfoForm, methodType, isDisabledbtn,
  activeName, setActiveName, handleChangeTabs, submitForm, handleClearData: cancelSubmit } = useTabsForm({
    id: '',
    customer_service_category_id: '',
    name: '',
    mobile: '',
    sort: 0
  }, disabledbtn, handleCustomOperation, formLoading);

let { handleSort } = useSort('putCustomerServiceSortInfo', searchInfo);

const rules = useRules('customerServicListRules');/* 校验规则 */
const state = reactive({
  selectCustomerClass: [],/* 客服类型 */
});
let { getListDataInfo } = useListData();
const id = ref(-1); /* 删除时所需的编号 删除时的id */

/* 点击编辑按钮 */
const handleViewEdit = (row, code) => {
  if ('view' === code) {
    isDisabledbtn.value = true;
  } else if ('edit' === code) {
    methodType.value = 'PUT';
  }
  /* 商品详情标签页显示 */
  activeName.value = 'two';
  mobilePhoneInfoForm.id = row.id;

  mobilePhoneInfoForm.mobile = row.mobile;
  mobilePhoneInfoForm.customer_service_category_id =
    row.customer_service_category_id;
  mobilePhoneInfoForm.name = row.name;

  mobilePhoneInfoForm.sort = row.sort;
}

/* 关闭切换标签页以后的自定义操作 */
function handleCustomOperation () {
  mobilePhoneInfoForm.id = '';
}

getTableInfo();
/* 获取客服类型信息 */
getListDataInfo('getCustomerServiceCategoryInfo', state, 'selectCustomerClass');
</script>

<style lang="scss" scoped>
/* layout-布局 */
// .el-row {
//   margin-bottom: 20px;
// }
.el-row:last-child {
  margin-bottom: 0;
}

.el-col {
  border-radius: 4px;
}

.bg-purple-dark {
  background: #99a9bf;
}

.bg-purple {
  background: #d3dce6;
}

.bg-purple-light {
  background: #e5e9f2;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
}

.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}

.handle-box {
  margin-bottom: 20px;
}

.handle-select {
  width: 120px;
}

.handle-input {
  width: 300px;
  display: inline-block;
}

.del-dialog-cnt {
  font-size: 16px;
  text-align: center;
}

.table {
  width: 100%;
  font-size: 14px;
}

.red {
  color: #ff0000;
}

.mr10 {
  margin-right: 10px;
}

.textAlignCenter {
  text-align: center;
}

/* 修改select的盒模型 */
.el-select {
  display: block;
}

/* 确定按钮的显示与隐藏 */
.displaybtn {
  display: none;
}

/* 修改该属性值  查询条件，查询结果得样式 */
.el-breadcrumb {
  border-bottom: 1px solid #ebeef5;
  padding-bottom: 10px;
}

/* 提示图标设置 */
.icon-wzg-config {
  height: 30px;
  line-height: 30px;
}

/* 底部按钮居中 */
.footer-center {
  margin: 10px 0;
  text-align: center;
}

/* 修改显示图片宽高 ,>>>用于修改组件中的css样式*/
// ::v-deep .el-upload--text,
// ::v-deep .el-upload--picture-card,
// ::v-deep .avatar-uploader-icon {
//   width: 345px;
//   height: 125px;
//   line-height: 125px;
// }
// ::v-deep .el-upload-list__item {
//   width: 345px;
//   height: 125px;
// }

/* 图片上传 start */
.w-spec .avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.w-spec :deep(.el-upload--text) {
  width: inherit;
}

.w-spec .avatar-uploader .el-upload:hover {
  border-color: #409eff;
}

.w-spec .avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.w-spec .avatar-uploader :deep(.el-upload--text) {
  height: inherit;
  padding: 2px 2px;
  color: #409eff;
}

.w-spec .wzg-continer-img {
  position: relative;
  display: inline-block;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;

  .wzg-img {
    width: inherit;
    height: inherit;
  }

  .el-icon-close {
    display: none;
  }
}

.w-spec .wzg-continer-img--ac,
.w-spec .avatar-uploader-icon--ac {
  width: 178px;
  height: 178px;
  line-height: 178px;
}

/* 图片删除按钮 start*/
.wzg-continer-img:hover .el-icon-close {
  position: absolute;
  top: 1px;
  right: -1px;
  z-index: 1000;
  display: inline-block;
  padding: 5px;
  cursor: pointer;
  background-color: rgba($color: #f00, $alpha: 0.8);
  color: #fff;
  border-radius: 2px;
  transition: 0.5s;
}

.w-spec .el-icon-close:hover {
  opacity: 0.8;
}
</style>
